package com.cz.mydao.controller;

import com.alibaba.excel.EasyExcel;
import com.cz.mydao.entity.StaffExcelVo;
import com.cz.mydao.service.ExcelService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 功能描述: Excel控制器
 *
 * @author: 程长
 * @date: 2025/1/17 11:41
 * @version: 1.0
 */
@RestController
@RequestMapping("/excel")
public class ExcelController {

    @Resource
    private ExcelService excelService;

    @GetMapping("/export")
    public void exportExcel(HttpServletResponse response) {
        excelService.export(response);
    }

    @PostMapping("/import")
    public List<StaffExcelVo> importExcel(@RequestParam("file") MultipartFile file) throws IOException {
        return EasyExcel.read(file.getInputStream())
                .head(StaffExcelVo.class)
                .sheet()
                .doReadSync();
    }

}
